package com.nw.game.controller;

import com.alibaba.fastjson.JSONObject;
import com.nw.game.service.LogicServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@CrossOrigin
@RestController
public class GameController {
    @Autowired
    LogicServer logicServer;
    @PostMapping(value = "/operation",consumes = "application/json",produces = "application/json;charset=utf-8")
    public String client(@RequestBody Map<String,Object> map){
        JSONObject jsonObject = new JSONObject(map);
        return logicServer.dispatch(jsonObject);
    }

    @GetMapping(value = "/algorithm")
    public String algorithm(HttpServletRequest request){
        JSONObject js = new JSONObject();
        js.put("operationCode",17);
        js.put("ID",request.getParameter("ID"));
        js.put("Payload",request.getParameter("Payload"));
        return logicServer.dispatch(js);
    }
}
